/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lu.med.praxiswahl.wahlumed.service.beans;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import lu.med.praxiswahl.wahlumed.dao.beans.daointerface.DoctorLettersTemplateDAOInt;
import lu.med.praxiswahl.wahlumed.model.beans.DoctorLettersTemplateTBL;
import lu.med.praxiswahl.wahlumed.service.beans.serviceinterface.DoctorLetterTemplateServiceInt;

/**
 * 
 * @author pkendzo
 */

@Stateless
@Remote({ DoctorLetterTemplateServiceInt.class })
public class DoctorLetterTemplateService implements
		DoctorLetterTemplateServiceInt {

	private DoctorLettersTemplateTBL tmpDocLetterTempl;
	@EJB
	private DoctorLettersTemplateDAOInt tmpDocLetterDao;

	public DoctorLetterTemplateService() {
		this.tmpDocLetterTempl = new DoctorLettersTemplateTBL();

	}

	@Override
	public int createDoctorLetterTemplate(String label, String typ, String text) {
		tmpDocLetterTempl.setLabel(label);
		tmpDocLetterTempl.setTyp(typ);
		tmpDocLetterTempl.setText(text);

		this.tmpDocLetterDao.persist(tmpDocLetterTempl);

		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public int deleteDoctorLetterTemplate(Long id) {
		this.tmpDocLetterDao.delete(id);

		return RET_OPERATION_DONE_PROPERLY;
	}

	@Override
	public void getA_DoctorLetterTemplateInstance(
			DoctorLettersTemplateTBL tmpDocLetterTempl) {
		this.tmpDocLetterTempl = tmpDocLetterTempl;

	}

	@Override
	public DoctorLettersTemplateTBL[] getAllDoctorLetterTemplate() {
		List<DoctorLettersTemplateTBL> tmp = this.tmpDocLetterDao
				.retrieveAllDoctorLetterTemplate();
		DoctorLettersTemplateTBL[] templateDoc = new DoctorLettersTemplateTBL[tmp
				.size()];

		for (int i = 0; i < tmp.size(); i++) {
			templateDoc[i] = tmp.get(i);
		}
		return templateDoc;
	}

	@Override
	public void getDoctorLetterTemplate(Long id) {
		// TODO Auto-generated method stub

	}

	@Override
	public String getDoctorLetterTemplateLabel(Long id) {
		return tmpDocLetterDao.retrieveDoctorLetterTemplateByID(id).getLabel();
	}

	@Override
	public String getDoctorLetterTemplateMainTxt(Long id) {
		return tmpDocLetterDao.retrieveDoctorLetterTemplateByID(id).getText();
	}

	@Override
	public Long[] getDoctorLetterVorlagenBy_Typ(String typ) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void updateActualDoctorLetterTemplate(Long id, String label,
			String text) {
		DoctorLettersTemplateTBL doc = tmpDocLetterDao
				.retrieveDoctorLetterTemplateByID(id);
		doc.setLabel(label);
		doc.setText(text);
		tmpDocLetterDao.update(doc);

	}

}
